To find the day from a particular date, you can use the modulo function with a date in the past that was a Monday.
For example, we know that the 7th of January 1980 was a Monday, so every 7th day after that is also a Monday. Subtracting this baseline date from the given date, and then using the modulo operator we can determine a number for each day of the week as follows:
the numerical form of the day of the week = (the date - 1980-01-07) modulo 7
This number can then be used in a rule table to find the day of the week:
| the day of the week | |
| "Monday" | the numerical form of day of the week = 0 |
| "Tuesday" | the numerical form of day of the week = 1 |
| "Wednesday" | the numerical form of day of the week = 2 |
| "Thursday" | the numerical form of day of the week = 3 |
| "Friday" | the numerical form of day of the week = 4 |
| "Saturday" | the numerical form of day of the week = 5 |
| "Sunday" | the numerical form of day of the week = 6 |
| uncertain | otherwise |
NOTE: Dates before the baseline date (eg before 1980-01-07) will give a negative modulo (ie Monday 0, Tuesday -6, Wednesday -5, Thursday -4, Friday -3, Saturday -2, Sunday -1). You can either choose to write rules to take this into account, or choose a baseline date so far in the past that it is unnecessary. If you want to take earlier dates into account, you would need a rule table like this:
| the day of the week | |
| "Monday" | the numerical form of day of the week = 0 |
| "Tuesday" |
the numerical form of day of the week = 1; or the numerical form of day of the week = -6 |
| "Wednesday" |
the numerical form of day of the week = 2; or the numerical form of day of the week = -5 |
| "Thursday" |
the numerical form of day of the week = 3; or the numerical form of day of the week = -4 |
| "Friday" |
the numerical form of day of the week = 4; or the numerical form of day of the week = -3 |
| "Saturday" |
the numerical form of day of the week = 5; or the numerical form of day of the week = -2 |
| "Sunday" |
the numerical form of day of the week = 6; or the numerical form of day of the week = -1 |
| uncertain | otherwise |